package com.ibo.htlivecamera.util;

import android.content.Context;
import android.media.AudioManager;

import com.ibo.htlivecamera.app.MyApplication;

public class Util {

    public static void controlVolume(int step) {
        //获取系统的Audio管理者
        AudioManager mAudioManager = (AudioManager) MyApplication.getInstance().getSystemService(Context.AUDIO_SERVICE);

        //当前音量
        int currentVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);

        currentVolume = Math.max(0, currentVolume + step);
        //最大音量
        int maxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
        currentVolume = Math.min(maxVolume, currentVolume);

        mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, currentVolume, AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND);
    }

}
